home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
STANDALO
/
BOUNCE_C
/
BOUNCEAB.C
< prev
next >
Wrap
Text File
|
1990-11-21
|
3KB
|
143 lines
/*
* bounceabout.c -- this file contains the routines to put up and housekeep the About
* Box. This code is harder to write than the cdev code it comments on! To put a
* LineBox object in this dialog required a filter proc. Since objects use the A4
* based jump table (in code resources), we must use Remember/SetUp/RestoreA4 if we
* want to make an object call from our filter proc. Plus, since we're using Modal-
* Dialog, not Alert, we have to draw the 'default frame' for our OK button.
*/
#include "bounce.h"
#include <SetUpA4.h>
/* prototypes for functions in this file */
pascal void DrawProc(DialogPtr, short);
pascal Boolean filter(DialogPtr, EventRecord *, short *);
void DoIdle(DialogPtr);
void DoCr(DialogPtr);
void DoUpdate(DialogPtr);
void FrameDefault(DialogPtr, int item);
/*
* This function puts up the dialog box and repeatedly calls ModalDialog.
*/
void BounceAbout(DialogPtr aboutBox, int type, Rect *box)
{
int itemHit;
RememberA4();
SetDItem(aboutBox, AboutBounceItem, type, (Handle)DrawProc, box);
ShowWindow((WindowPtr) aboutBox);
do {
ModalDialog(filter, &itemHit);
} while (itemHit != OKItem);
}
/*
* This function calls the LineBox's Draw routine.
*/
static pascal void DrawProc(DialogPtr dp, short item)
{
SetUpA4();
((LineBox *)GetWRefCon((WindowPtr) dp))->Draw();
RestoreA4();
}
/*
* This is the ModalDialog filter proc. It responds to update and keyDown events,
* and during nullEvents it calls the LineBox's idle procedure.
*/
static pascal
Boolean filter(DialogPtr theDialog, EventRecord *theEvent, short *itemHit)
{
long keyhit;
Boolean result = FALSE;
switch(theEvent->what) {
case updateEvt:
if ((DialogPtr)theEvent->message == theDialog) {
DoUpdate(theDialog);
*itemHit = 0;
result = TRUE;
}
break;
case keyDown:
keyhit = theEvent->message & charCodeMask;
if (keyhit == 0x3 || keyhit == 0xd) {
DoCr(theDialog);
*itemHit = OKItem;
result = TRUE;
}
break;
case nullEvent:
DoIdle(theDialog);
break;
default:
break;
}
return result;
}
/*
* During idle time, call the LineBox's Idle procedure to bounce the line.
*/
static void DoIdle(DialogPtr theDialog)
{
SetUpA4();
((LineBox *)GetWRefCon((WindowPtr) theDialog))->Idle();
RestoreA4();
}
/*
* This function handles the user hitting return or enter. It selects the
* OK button with HiliteControl, then waits for a bit so the user can see it.
*/
static void DoCr(DialogPtr theDialog)
{
ControlHandle okButton;
int type;
Rect box;
long dummy;
GetDItem(theDialog, OKItem, &type, (Handle *)&okButton, &box);
HiliteControl(okButton, 1);
Delay(3, &dummy);
}
/*
* Since we want to draw a button outline, we have to take care of all the
* update drawing for our dialog. (Of course, one could use a UserItem with
* a Draw proc...)
*/
static void DoUpdate(DialogPtr theDialog)
{
GrafPtr savePort;
GetPort(&savePort);
SetPort(theDialog);
BeginUpdate(theDialog);
UpdtDialog(theDialog, theDialog->visRgn);
FrameDefault(theDialog, OKItem);
EndUpdate(theDialog);
SetPort(savePort);
}
/*
* Frame the OK button with a nice bold outline. This is from IM I-407.
*/
static void FrameDefault(DialogPtr dlog, int item)
{
int type;
Handle hndl;
Rect box;
PenState savePen;
GetPenState(&savePen);
PenNormal();
GetDItem(dlog, item, &type, &hndl, &box);
PenSize(3, 3);
InsetRect(&box, -4, -4);
FrameRoundRect(&box, 16, 16);
SetPenState(&savePen);
}